package com.loeng.module.system.dal.mysql.social;

import com.loeng.framework.common.pojo.PageResult;
import com.loeng.framework.mybatis.core.mapper.BaseMapperX;
import com.loeng.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.loeng.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
import com.loeng.module.system.dal.dataobject.social.SocialClientDO;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface SocialClientMapper extends BaseMapperX<SocialClientDO> {

    /**
     * 根据社交类型和用户类型，获得对应的社交用户
     *
     * @param socialType 社交类型
     * @param userType 用户类型
     * @return 社交用户
     */
    default SocialClientDO selectBySocialTypeAndUserType(Integer socialType, Integer userType) {
        return selectOne(SocialClientDO::getSocialType, socialType,
                SocialClientDO::getUserType, userType);
    }

    /**
     * 获得社交客户端分页
     *
     * @param reqVO 分页条件
     * @return 分页结果
     */
    default PageResult<SocialClientDO> selectPage(SocialClientPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SocialClientDO>()
                .likeIfPresent(SocialClientDO::getName, reqVO.getName())
                .eqIfPresent(SocialClientDO::getSocialType, reqVO.getSocialType())
                .eqIfPresent(SocialClientDO::getUserType, reqVO.getUserType())
                .orderByDesc(SocialClientDO::getId));
    }

}
